package cn.stazxr.component;

import java.awt.*;

/**
 * Package: cn.stazxr.component
 * ClassName: CheckboxTest
 * @Author: stazxr
 * @Create: 2023/12/2
 * @Version: v1.0
 **/
public class CheckboxTest {
    public static void main(String[] args) {
        Frame frame = new Frame("Hello world!");
        frame.setBounds(500, 300, 600, 400);
        frame.setFont(new Font("Microsoft YaHei UI", Font.ITALIC, 15));
        frame.setLayout(null);

        Checkbox checkbox = new Checkbox("remember password");
        checkbox.setBounds(100, 100, 200, 50);
        frame.add(checkbox);

        TextArea textArea = new TextArea();
        textArea.setBounds(100, 150, 200, 100);
        frame.add(textArea);

        CheckboxGroup group = new CheckboxGroup();   //创建勾选框组

        Checkbox c1 = new Checkbox("Hi~");
        c1.setBounds(20, 50, 100, 30);
        frame.add(c1);

        Checkbox c2 = new Checkbox("Hello~");
        c2.setBounds(20, 80, 100, 30);
        frame.add(c2);

        Button button = new Button("login");
        button.setBounds(150, 300, 100, 50);
        button.addActionListener(e->{
            System.out.println(checkbox.getState());
            System.out.println(textArea.getText());
            System.out.println(group.getSelectedCheckbox().getLabel());
        });
        frame.add(button);

        c1.setCheckboxGroup(group);    //多个勾选框都可以添加到勾选框组中
        c2.setCheckboxGroup(group);
        frame.setVisible(true);
    }
}
